﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace SBPweb.PhotoGallery.Client
{

    [ContentProperty("Content")]
    public class ImageButton : ContentControl
    {

        public static readonly DependencyProperty SourceProperty;

        #region Private fields

        private Storyboard sbEnter;
        private Storyboard sbLeave;

        #endregion

        #region Constructor logic

        public ImageButton()
        {
            InitializeStoryBoard();
            this.DefaultStyleKey = typeof(ImageButton);
            this.MouseEnter += new System.Windows.Input.MouseEventHandler(ImageButton_MouseEnter);
            this.MouseLeave += new System.Windows.Input.MouseEventHandler(ImageButton_MouseLeave);
        }

        #endregion

        #region Property accessors

        public ImageSource Source
        {
            get;
            set;
        }

        #endregion

        #region Methods

        private void InitializeStoryBoard()
        {
            sbEnter = new Storyboard();
            sbLeave = new Storyboard();
            
            DoubleAnimation dAEnter = new DoubleAnimation();
            dAEnter.From = 0.7;
            dAEnter.To = 1;
            dAEnter.Duration = new Duration(TimeSpan.FromSeconds(0.3));
            sbEnter.Children.Add(sbEnter);

            DoubleAnimation dALeave = new DoubleAnimation();
            dALeave.From = 1;
            dALeave.To = 0.7;
            dALeave.Duration = new Duration(TimeSpan.FromSeconds(1));
            sbLeave.Children.Add(sbEnter);

            Storyboard.SetTarget(dALeave, this);
        }

        private void ImageButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            sbEnter.Begin();
        }

        private void ImageButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            sbLeave.Begin();
        }

        #endregion

    }

}